#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <iterator>
#include <sstream>
using namespace std;
vector<int>ans;
int n, m;
vector<int>vis;
void dfs(int x)
{
	if (x == m)
	{
		copy(ans.begin(), ans.end(), ostream_iterator<int>(cout)); 
		cout << endl;
		return;
	}
	for (int i = 1; i <= n; i++)
	{
		if (vis[i] == 0)
		{
			vis[i] = 1;
			ans.push_back(i);
			dfs(x + 1);
			ans.pop_back();
			vis[i] = 0;
		}
	}
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n >> m;
		vis.resize(n + 1, 0);
		dfs(0);
	}
	return 0;
}